import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ManagerService } from './../../service/manager.service';
import { User } from 'src/app/domain/user';
import { AuthService } from '../../service/auth.service';
/*

@Author:赵明洋

@Date: 2018-12-12

@员工主界面功能实现

@Last Modified time: 2018-12-16
*/
@Component({
  selector: 'app-staff-main',
  templateUrl: './staff-main.component.html',
  styleUrls: ['./staff-main.component.css']
})
export class StaffMainComponent implements OnInit {
  user:User;
  menus:Array<Menu>;
  currentMenuID:number;
  private date = new Date();
  constructor(public router :Router , private managerService: ManagerService) {

   }

  ngOnInit() {
    this.menus =[
      new Menu(1,'首页','staff'),
      new Menu(2,'打卡详情','staff/signin'),
      new Menu(3,'外出申请状态查询','staff/outrequeststate'),
      new Menu(3,'请假申请状态查询','staff/leaverequeststate'),

    ];
    this.getUser();
  }
  getUser(){
    var id = AuthService.getUserId();
    if(id == 0){
      alert("请先登录");
    }
    else{
      this.managerService.getUser(id)
      .subscribe(date=>this.user = date[0]);
    
    }
    }

  
  nav(menu:Menu)
  {
    this.router.navigateByUrl(menu.link);
    this.currentMenuID= menu.id;
  }
  navv(url:string)
  {
    this.router.navigateByUrl(url);
   
  }

  getNum() : number{
    return (Math.round(10000*this.user.remain_annual_leave/this.user.annual_leave_length)/100);
  }

}
export class Menu{
  constructor(
    public id:number,
    public name:string,
    public link:string
  )
  {

  }
}